package com.jz.community.moduleshopping.orderDetail.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.RxTimeTool;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.orderDetail.bean.OrderTrackInfo;
import com.jz.community.moduleshopping.orderList.enums.OrderStatusType;

import java.util.List;

/**
 * Created by Ani_H on 2018/2/1.
 */
public class OrderTrackAdapter extends BaseQuickAdapter<OrderTrackInfo.EmbeddedBean.ContentBean, BaseViewHolder> {

    public OrderTrackAdapter(int layoutResId, @Nullable List<OrderTrackInfo.EmbeddedBean.ContentBean> data) {
        super(layoutResId, data);
        mData = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderTrackInfo.EmbeddedBean.ContentBean entity) {

        ImageView iv = helper.getView(R.id.item_order_track_iv);//图片或圆点
        View line_top = helper.getView(R.id.item_order_track_line_top);//top线
        View line_bot = helper.getView(R.id.item_order_track_line_bot);//bot线
        LinearLayout content_ll = helper.getView(R.id.item_order_track_content_ll);//内容的ll
        TextView content = helper.getView(R.id.item_order_track_content);//内容
        TextView time = helper.getView(R.id.item_order_track_time);//时间


        int type = 0;

        if (helper.getAdapterPosition() == 0) {

            content.setTextColor(mContext.getResources().getColor(R.color.home_red));
            time.setTextColor(mContext.getResources().getColor(R.color.home_red));

            if (!Preconditions.isNullOrEmpty(entity.getStatus())){
                if (entity.getStatus().equals(OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus())) {
                    //订单生成
                    iv.setImageResource(R.mipmap.order_track_one);
                } else if (entity.getStatus().equals(OrderStatusType.ORDER_ALREADY_PAY_STATUS.getOrderStatus())) {
                    //已支付
                    iv.setImageResource(R.mipmap.order_track_two);
                } else if (entity.getStatus().equals(OrderStatusType.ORDER_RECEIPT_STATUS.getOrderStatus())) {
                    //已接单
                    iv.setImageResource(R.mipmap.order_track_three);
                } else {
                    iv.setImageResource(R.mipmap.red_point);
                }
            }else {
                iv.setImageResource(R.mipmap.red_point);
            }

        } else {
            content.setTextColor(mContext.getResources().getColor(R.color.font_gary));
            time.setTextColor(mContext.getResources().getColor(R.color.font_gary));

            if (!Preconditions.isNullOrEmpty(entity.getStatus())){
                if (entity.getStatus().equals(OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus())) {
                    //订单生成
                    iv.setImageResource(R.mipmap.order_track_one);
                } else if (entity.getStatus().equals(OrderStatusType.ORDER_ALREADY_PAY_STATUS.getOrderStatus())) {
                    //已支付
                    iv.setImageResource(R.mipmap.order_track_two);
                } else if (entity.getStatus().equals(OrderStatusType.ORDER_RECEIPT_STATUS.getOrderStatus())) {
                    //已接单
                    iv.setImageResource(R.mipmap.order_track_three);
                } else {
                    iv.setImageResource(R.mipmap.gray_point);
                }
            }else {
                iv.setImageResource(R.mipmap.gray_point);
            }
        }

        content.setText(entity.getInfo());
        time.setText(entity.getCreateDate());

        if (helper.getAdapterPosition() == 0) {
            //第0个不显示Top线
            line_top.setVisibility(View.GONE);
            if (type == 0) {
                //iv为小圆点

                //ll
                LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) content_ll.getLayoutParams();
                lp.setMargins(0, SHelper.dp2px(mContext, 10), 0, 0);
                content_ll.setLayoutParams(lp);

                //iv
                LinearLayout.LayoutParams lp_iv = (LinearLayout.LayoutParams) iv.getLayoutParams();
                lp_iv.setMargins(0, SHelper.dp2px(mContext, 15), 0, 0);
                iv.setLayoutParams(lp_iv);
            } else {
                //iv为图片

                //ll
                LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) content_ll.getLayoutParams();
                lp.setMargins(0, SHelper.dp2px(mContext, 15), 0, 0);
                content_ll.setLayoutParams(lp);

                //iv
                LinearLayout.LayoutParams lp_iv = (LinearLayout.LayoutParams) iv.getLayoutParams();
                lp_iv.setMargins(0, SHelper.dp2px(mContext, 10), 0, 0);
                iv.setLayoutParams(lp_iv);
            }

        } else {
            line_top.setVisibility(View.VISIBLE);

            if (type == 0) {
                LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) content_ll.getLayoutParams();
                lp.setMargins(0, SHelper.dp2px(mContext, 12), 0, 0);
                content_ll.setLayoutParams(lp);
            } else {
                LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) content_ll.getLayoutParams();
                lp.setMargins(0, SHelper.dp2px(mContext, 20), 0, 0);
                content_ll.setLayoutParams(lp);
            }
        }

        //最后一条没有Bot线
        if (helper.getAdapterPosition() == mData.size() - 1) {
            line_bot.setVisibility(View.GONE);
        } else {
            line_bot.setVisibility(View.VISIBLE);
        }

    }
}
